package com.rjpacket.supernews.app.adapters;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.rjpacket.supernews.app.NewsSearchActivity;
import com.rjpacket.supernews.app.R;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2015/3/13 0013.
 */
public class SearchAdapter extends BaseAdapter {
    private List<List<String>> list;
    private Context context;
    private int layoutId;
    List<String> sublist = new LinkedList<String>();

    public SearchAdapter(Context context, List<List<String>> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        View ret = null;


        if (list.get(i).size() == 1) {
            layoutId = R.layout.item_search_news_1;
        } else {
            layoutId = R.layout.item_search_news;
        }
        ret = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);

        ViewHolder holder = (ViewHolder) ret.getTag();

        if (holder == null) {
            holder = new ViewHolder();
            holder.txt1 = (TextView) ret.findViewById(R.id.search_txt1);
            holder.txt2 = (TextView) ret.findViewById(R.id.search_txt2);
            holder.txt_1 = (TextView) ret.findViewById(R.id.search_txt_1);

            ret.setTag(holder);
        }

        sublist = list.get(i);
        if (sublist.size() > 1) {


            holder.txt1.setText(sublist.get(0));

            holder.txt2.setText(sublist.get(1));
        } else {
            holder.txt_1.setText(sublist.get(0));
        }

     /*   final ImageView img = (ImageView)ret.findViewById(R.id.search_image_btn_02);
        holder.txt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (context instanceof NewsSearchActivity){
                    ((NewsSearchActivity)context).ImageOnClick(img);
                }
            }
        });
        holder.txt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (context instanceof NewsSearchActivity){
                    ((NewsSearchActivity)context).ImageOnClick(img);
                }
            }
        });
        holder.txt_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (context instanceof NewsSearchActivity){
                    ((NewsSearchActivity)context).ImageOnClick(img);
                }
            }
        });*/
        return ret;
    }


    /*public void refreshList(List<List<String>>  data) {
        list = data;
    }*/

    private class ViewHolder {
        private TextView txt1;
        private TextView txt2;
        private TextView txt_1;

    }
}
